package com.dituo.esac.mybatis;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import com.dituo.esac.enums.HousePropertyEnums;

public class HousePropertyHandler extends BaseTypeHandler<String> {

	@Override
	public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType)
			throws SQLException {
		// 设置查询参数，一般用不上	
		ps.setInt(i, (null == parameter ? 0 : Integer.parseInt(parameter)));
	}

	@Override
	public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
		// null值为0
		int code = rs.getInt(columnName);
		return HousePropertyEnums.getDescByCode(code);
	}

	@Override
	public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
		// null值为0
		int code = rs.getInt(columnIndex);
		return HousePropertyEnums.getDescByCode(code);
	}

	@Override
	public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
		// null值为0
		int code = cs.getInt(columnIndex);
		return HousePropertyEnums.getDescByCode(code);
	}

}
